
class Classmate(object):
    def __init__(self):
        self.names = list()
        self.cur_num = 0

    def add(self,name):
        self.names.append(name)

    def __iter__(self):
        """重写该方法以实现让对象可迭代"""
        return self

    def __next__(self):
        if self.cur_num < len(self.names):
            res = self.names[self.cur_num]
            self.cur_num += 1
            return res
        else:
            raise StopIteration

if __name__ == '__main__':

    classmate = Classmate()

    classmate.add("123")
    classmate.add("qaz")
    classmate.add("wsx")

    for name in classmate:
        print(name)

